package frame.networks.viewers;

import java.awt.BorderLayout;
import java.awt.Color;

import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.SwingConstants;

import model.components.links.link.Link;
import model.components.networks.virtual.VirtualNetwork;
import model.components.nodes.comparator.NodeNumberComparator;
import model.components.nodes.node.Node;
import edu.uci.ics.jung.algorithms.layout.CircleLayout;
import frame.SimulatorFrame;
import frame.networks.viewers.viewer.NetworkVisualizationViewer;

@SuppressWarnings("serial")
public class VirtualVisualizationViewersTabbedPane extends JTabbedPane
{
	private SimulatorFrame simulatorFrame;
	public SimulatorFrame getFrame(){ return simulatorFrame; }
	public void setFrame( SimulatorFrame simulatorFrame ){ this.simulatorFrame = simulatorFrame; }
	
	public VirtualVisualizationViewersTabbedPane( SimulatorFrame simulatorFrame )
	{
		this.setFrame( simulatorFrame );
		
		this.setTabPlacement( SwingConstants.TOP );
		
		for( VirtualNetwork virtualNetwork: simulatorFrame.getSimulator().getVirtualNetworks() )
			this.addVirtualNetworkTab( virtualNetwork );
	}
	
	public void addVirtualNetworkTab( VirtualNetwork virtualNetwork )
	{
		CircleLayout< Node, Link > circleLayout = new CircleLayout< Node, Link >( virtualNetwork.getGraph() );
		circleLayout.setVertexOrder( new NodeNumberComparator() );
		
		NetworkVisualizationViewer networkVisualizationViewer = new NetworkVisualizationViewer( circleLayout, this.getFrame() );
		networkVisualizationViewer.setBackground( Color.WHITE );
		
		JPanel panel = new JPanel( new BorderLayout() );
		panel.add( networkVisualizationViewer );
		this.addTab( virtualNetwork.getName(), null, panel, null );
	}

}